package com.ysd.crm.model;

import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.fasterxml.jackson.annotation.JsonIgnore;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Entity
@Table
@Getter
@Setter
@ToString
public class Users {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer uid;//主键
	@Column(length = 20,nullable = false)
	private String uname;//用户名，不能为空
	@Column(length = 20,nullable = false)
	private String upass;//密码，不能为空
	@Column(columnDefinition = "char(2) default '否'",insertable = false)
	private String isLockout;//是否锁定
	private Timestamp lastLoginTime;//最后登录时间
	@Column(columnDefinition = "int default 0",insertable = false)
	private Integer psdWrongTime;//登录错误次数，新增时不插入该字段，采用默认值0
	private Timestamp lockTime;//账号锁定时间
	@Column(columnDefinition = "datetime default now()",insertable = false,updatable = false)
	private Timestamp createTime;//创建时间
	@Column(columnDefinition = "int default 0",insertable = false)
	private Integer loginState;//登录状态,0表示没登录
	
	@ManyToMany
	@Cascade(CascadeType.SAVE_UPDATE)
	@JoinTable(name = "user_role_tb",joinColumns = @JoinColumn(name="user_id"),inverseJoinColumns = @JoinColumn(name="role_id"))
	@NotFound(action = NotFoundAction.IGNORE)
	private Set<Roles> roleSet = new HashSet<Roles>();
}
